/*
 *  Copyright 2008-2009 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <cusp/graph/detail/dispatch/partition.h>

namespace cusp
{
namespace graph
{
namespace detail
{

// CSR format 
template <typename PartitionerType, typename MethodType,
	  typename MatrixType, typename ArrayType >
size_t partition(const MatrixType& graph, 
                       size_t num_parts,  
                       ArrayType& part,                 
                       bool Kway,
		       cusp::csr_format)
{
    return cusp::graph::detail::dispatch::partition<PartitionerType,MethodType>(graph, num_parts, part, Kway,
                            	    typename MatrixType::memory_space());
}

// Default case uses CSR transpose
template <typename PartitionerType, typename MethodType,
	  typename MatrixType, typename ArrayType, typename MatrixFormat >
size_t partition(const MatrixType& graph, 
                       size_t num_parts,  
                       ArrayType& part,                 
                       bool Kway,
		       MatrixFormat)
{
    typedef typename MatrixType::index_type   IndexType;
    typedef typename MatrixType::value_type   ValueType;
    typedef typename MatrixType::memory_space MemorySpace;

    cusp::csr_matrix<IndexType, ValueType, MemorySpace> graph_csr(graph);
    return cusp::graph::partition<PartitionerType,MethodType>(graph_csr, num_parts, part, Kway);
}

} // end namespace detail

template <typename PartitionerType, typename MethodType,
	  typename MatrixType, typename ArrayType >
size_t partition(const MatrixType& graph, 
                       size_t num_parts,  
                       ArrayType& part,                 
                       bool Kway)
{
    CUSP_PROFILE_SCOPED();

    return cusp::graph::detail::partition<PartitionerType, MethodType>(graph, num_parts, part, Kway,
                            	   typename MatrixType::format());
}

} // end namespace graph
} // end namespace cusp

